package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.pojo.dto.orderDto.OrderUpdateDto;
import com.itheima.pojo.vo.orderVo.OrderByPageVo;
import com.itheima.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private OrderService orderService;
    @GetMapping("/page")
    public R selectByPage(String number ,int page,
                          int pageSize,
                          String endTime,
                          String beginTime) throws ParseException {
        List<OrderByPageVo> list = orderService.selectByPage(page, pageSize, number, endTime, beginTime);
        Map<String,Object>map=new HashMap<>();
        map.put("records", list);
        map.put("total", (page-1)*pageSize);
        map.put("size", pageSize);
        map.put("current", page);
        return R.success(map);
    }
    @PutMapping
    public R update(@RequestBody OrderUpdateDto order){

        boolean update = orderService.update(order);
        if (update){
            return R.success("修改成功");
        }
        return R.error("修改失败");
    }
}
